/* Copyright ©, 2022, ECARX (Hubei) Technology Co., Ltd. All rights reserved.
 *
 * NOTICE: This file contains information which is confidential and proprietary to ECARX
 * (Hubei) Technology Co., Ltd. and/or other developers. No license to any intellectual
 * property rights contained within this file is either granted or implied except as may be
 * provided in an agreement with ECARX (Hubei) Technology Co., Ltd.
 *
 * Any unauthorized copying or distribution of content from this file in whole or in part
 * is prohibited.
 */
#ifndef ECARX_VHAL_CORE_PERSIST_PROPERTIES_H
#define ECARX_VHAL_CORE_PERSIST_PROPERTIES_H

#include <memory>
#include <shared_mutex>
#include <string>
#include <vector>
#include <utils/Looper.h>

namespace ecarx::vhal::core::persist {
class Properties{
    class Persist;
    std::unique_ptr<Persist> mPersist;
    std::string mFilePath;
    bool changed;
    bool isDeleted;
    android::sp<android::MessageHandler> mMessageHandler;
    std::shared_mutex mRWMutex;

  protected:
    const std::string& getFilePath() const;

  public:
    Properties(const char* path,const char* name);
    virtual ~Properties();
    void save();
    bool deleteFile();

    std::string getString(const std::string& key, const std::string& def) ;
    void setString(const std::string& key, const std::string& value) ;

    int32_t getInt32(const std::string& key, int32_t def) ;
    void setInt32(const std::string& key, int32_t value) ;

    std::vector<int32_t> getInt32Array(const std::string& key,
                                       const std::vector<int32_t>& def) ;
    void setInt32Array(const std::string& key, const std::vector<int32_t>& value) ;

    int64_t getInt64(const std::string& key, int64_t def) ;
    void setInt64(const std::string& key, int64_t value) ;

    std::vector<int64_t> getInt64Array(const std::string& key,
                                       const std::vector<int64_t>& def) ;
    void setInt64Array(const std::string& key, const std::vector<int64_t>& value) ;

    float getFloat(const std::string& key, float def) ;
    void setFloat(const std::string& key, float value) ;

    std::vector<float> getFloatArray(const std::string& key, const std::vector<float>& def) ;
    void setFloatArray(const std::string& key, const std::vector<float>& value) ;

    std::vector<uint8_t> getBytes(const std::string& key, const std::vector<uint8_t>& def) ;
    void setBytes(const std::string& key, const std::vector<uint8_t>& value) ;

    bool getBool(const std::string& key, const bool def) ;
    void setBool(const std::string& key, const bool value) ;

    bool hasProperty(const std::string& key) ;
};

}  // namespace ecarx::vhal::core::persist

#endif